package org.example.rmsmsapi.netManager;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLSession;

/**
 * Created by 黄启位 on 2022-04-04.
 */
public class OkHttpHostnameVerifier  implements  HostnameVerifier{
    /**
     * OkHttp验证主机名
     *
     * @return false 不信任主机
     * 默认 false
     */

    @Override
    public boolean verify(String hostname, SSLSession session) {

        /**
         * 这里验证主机名是XXX.XXX.com就返回true。信任这个域名。也可以结合白名单等动态校验。
         * */

        if ("www.lszyktwx.com".equals(hostname)) {
            return true;
        } else {
            HostnameVerifier hv = HttpsURLConnection.getDefaultHostnameVerifier();
            return hv.verify(hostname, session);
        }
    }
}
